home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / printtestpagedialog.py < prev    next >
Text File  |  2009-10-09  |  5KB  |  158 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2008 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22.  
  23. # Local
  24. from base.g import *
  25. from base import device
  26. from ui_utils import *
  27.  
  28. # Qt
  29. from PyQt4.QtCore import *
  30. from PyQt4.QtGui import *
  31.  
  32. # Ui
  33. from printtestpagedialog_base import Ui_Dialog
  34.  
  35.  
  36. class PrintTestPageDialog(QDialog, Ui_Dialog):
  37.     def __init__(self, parent, printer_name):
  38.         QDialog.__init__(self, parent)
  39.  
  40.         self.printer_name = printer_name
  41.         self.device_uri = ''
  42.         self.setupUi(self)
  43.         self.initUi()
  44.  
  45.         QTimer.singleShot(0, self.updateUi)
  46.  
  47.  
  48.     def initUi(self):
  49.         #print "PrintTestPageDialog.initUi()"
  50.         self.HPLIPTestPageRadioButton.setChecked(True)
  51.         self.LoadPaper.setButtonName(self.__tr("Print Test Page"))
  52.  
  53.         self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
  54.         self.connect(self.PrintTestpageButton, SIGNAL("clicked()"), self.PrintTestpageButton_clicked)
  55.  
  56.         self.connect(self.PrinterNameCombo, SIGNAL("PrinterNameComboBox_currentChanged"),
  57.             self.PrinterNameCombo_currentChanged)
  58.  
  59.         self.connect(self.PrinterNameCombo, SIGNAL("PrinterNameComboBox_noPrinters"),
  60.             self.PrinterNameComboBox_noPrinters)
  61.  
  62.         if self.printer_name:
  63.             self.PrinterNameCombo.setInitialPrinter(self.printer_name)
  64.  
  65.         # Application icon
  66.         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
  67.  
  68.  
  69.     def updateUi(self):
  70.         self.PrinterNameCombo.updateUi()
  71.         self.LoadPaper.updateUi()
  72.         #self.updatePrintButton()
  73.  
  74.  
  75.     def PrinterNameComboBox_noPrinters(self):
  76.         FailureUI(self, self.__tr("<b>No printers found.</b><p>Please setup a printer and try again."))
  77.         self.close()
  78.  
  79.  
  80.     def updatePrintButton(self):
  81.         QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
  82.         self.PrintTestpageButton.setEnabled(False)
  83.         ok = False
  84.         try:
  85.             try:
  86.                 d = device.Device(self.device_uri, self.printer_name)
  87.             except Error, e:
  88.                 log.error("Device error (%s)." % e.msg)
  89.             else:
  90.                 try:
  91.                     d.open()
  92.                 except Error:
  93.                     log.error("Unable to print to printer. Please check device and try again.")
  94.                 else:
  95.                     ok = d.isIdleAndNoError()
  96.  
  97.             self.PrintTestpageButton.setEnabled(ok)
  98.  
  99.             if not ok:
  100.                 QApplication.restoreOverrideCursor()
  101.                 FailureUI(self, self.__tr("<b>Unable to communicate with printer %1.</b><p>Please check the printer and try again.").arg(self.printer_name))
  102.  
  103.             d.close()
  104.  
  105.         finally:
  106.             QApplication.restoreOverrideCursor()
  107.  
  108.  
  109.     def CancelButton_clicked(self):
  110.         self.close()
  111.  
  112.  
  113.     def PrinterNameCombo_currentChanged(self, device_uri, printer_name):
  114.         self.printer_name = printer_name
  115.         self.device_uri = device_uri
  116.         self.updatePrintButton()
  117.         #self.updateUi()
  118.  
  119.  
  120.     def PrintTestpageButton_clicked(self):
  121.         QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
  122.         ok = False
  123.         try:
  124.             try:
  125.                 d = device.Device(self.device_uri, self.printer_name)
  126.             except Error, e:
  127.                 log.error("Device error (%s)." % e.msg)
  128.             else:
  129.                 try:
  130.                     d.open()
  131.                 except Error:
  132.                     log.error("Unable to print to printer. Please check device and try again.")
  133.                 else:
  134.                     ok = d.isIdleAndNoError()
  135.  
  136.         finally:
  137.             QApplication.restoreOverrideCursor()
  138.  
  139.         if ok:
  140.             QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
  141.             try:
  142.                 d.printTestPage(self.printer_name)
  143.             finally:
  144.                 QApplication.restoreOverrideCursor()
  145.  
  146.             self.close()
  147.  
  148.         else:
  149.             FailureUI(self, self.__tr("<b>A error occured sending the test page to printer %1.</b><p>Please check the printer and try again.").arg(self.printer_name))
  150.  
  151.         d.close()
  152.  
  153.  
  154.     def __tr(self, s, c=None):
  155.         return qApp.translate("PrintTestPageDialog", s, c)
  156.  
  157.  
  158.